Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only enable IOCP notifications in Process#wait, not .new #14995

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HertzDevil
Copy link
Contributor

On Windows, Processes could be garbage-collected before their completion events are received, meaning Crystal::IOCP.wait_queued_completions could receive invalid objects: (note that Process doesn't require explicit uses of LibC.PostQueuedCompletionStatus or Crystal::IOCP::OverlappedOperation)

200.times do
  Process.new("hostname.exe")
end

10.times { GC.collect }

`hostname`
Invalid memory access (C0000005) at address 0x2e07fca2f68
[0x7ff73d503cc0] run at C:\crystal\src\crystal\system\win32\iocp.cr:48
[0x7ff73d5011a4] reschedule at C:\crystal\src\crystal\scheduler.cr:160
[0x7ff73d5015b7] sleep at C:\crystal\src\crystal\scheduler.cr:168
[0x7ff73d50154e] sleep at C:\crystal\src\crystal\scheduler.cr:65
[0x7ff73d47120d] sleep at C:\crystal\src\concurrent.cr:23
[0x7ff73d471306] -> at C:\crystal\src\crystal\system\win32\process.cr:208
[0x7ff73d4fba28] run at C:\crystal\src\fiber.cr:143
[0x7ff73d4715d9] -> at C:\crystal\src\fiber.cr:95

This PR ensures those events are not enabled until Process#wait is called. Previous lost events do not matter as we first use LibC.GetExitCodeProcess to determine if the process has already exited.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:system labels Sep 12, 2024
@HertzDevil HertzDevil marked this pull request as draft September 12, 2024 19:23
@straight-shoota straight-shoota linked an issue Sep 25, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows Windows support based on the MSVC toolchain / Win32 API topic:stdlib:system
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

Invalid memory access in Windows CI
1 participant